﻿using System;
using SharedLibraries;
using SharedLibraries.Constants;
using ThangNM_LIB.DB;
using ThangNM_LIB.EO;
using ThangNM_LIB.FUNC;

namespace ThangNM
{
    public partial class Author : System.Web.UI.Page
    {
        public ThangNM.PublicInterface.Home_New mtpHome;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                mtpHome = Master as ThangNM.PublicInterface.Home_New;
                mtpHome.setClearMsg();
                if (!IsPostBack)
                {
                    if (Request.QueryString[QueryString.username] != null)
                    {
                        AccountEO _AccountEO = new AccountEO();
                        Int32 iUID = 0;
                        if (Int32.TryParse(StringEx.Trim(StringEx.Trim(Request.QueryString[QueryString.username])), out iUID))
                        {
                            _AccountEO.PK_iAccountID = iUID;
                            _AccountEO = (new ShareDAO.UserDAO()).SelectItem(_AccountEO.PK_iAccountID, null);
                        }
                        else
                            _AccountEO = (new ShareDAO.UserDAO()).SelectItem(0, StringEx.Trim(Request.QueryString[QueryString.username]).ToLower());
                        if (_AccountEO == null)
                        {
                            Commons.setRedirect(Page, null);
                            return;
                        }
                        if (!StringEx.Compare(Request.RawUrl.Substring(1), _AccountEO.sUrlRewrite))
                        {
                            Commons.setRedirect(Page, _AccountEO.sUrlRewrite);
                            return;
                        }
                        Commons.setSEO_ON_PAGE(Page, _AccountEO, this.GetType());
                        ArticleUC1.BindData_Author(_AccountEO);
                        ArticleUC1.BindData_Common(null, null, _AccountEO, true);
                    }
                }
            }
            catch (Exception ex)
            {
                if (mtpHome != null)
                    mtpHome.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex.Message, e.ToString());
            }
        }
    }
}